832661a062ab87dcf8d28acb3ca53dd611d79b0a,AIMSICD/src/main/java/com/secupwn/aimsicd/smsdetection/SmsDetector.java,SmsDetector,parseMwiSms,#String[]#String#,318

Before Change



    private void parseMwiSms(String[] logcatLines, String logcat_timestamp) {

        CapturedSmsData capturedSms = new CapturedSmsData();
        String smsText = findSmsData(logcatLines, null);
        String num = findSmsNumber(logcatLines, null);

        capturedSms.setSenderNumber(num == null ? "null" : num);
        capturedSms.setSenderMsg(smsText == null ? "null" : smsText);
        capturedSms.setSmsTimestamp(logcat_timestamp);
        capturedSms.setSmsType("MWI");
        capturedSms.setCurrent_lac(mAIMSICDService.getCellTracker().getMonitorCell().getLac());
        capturedSms.setCurrent_cid(mAIMSICDService.getCellTracker().getMonitorCell().getCid());
        capturedSms.setCurrent_nettype(mAIMSICDService.getCell().getRat());
        int isRoaming = 0;
        if (mAIMSICDService.getCellTracker().getDevice().isRoaming()) {
            isRoaming = 1;
        }
        capturedSms.setCurrent_roam_status(isRoaming);
        capturedSms.setCurrent_gps_lat(mAIMSICDService.lastKnownLocation().getLatitudeInDegrees());
        capturedSms.setCurrent_gps_lon(mAIMSICDService.lastKnownLocation().getLongitudeInDegrees());

        //only alert if timestamp is not in the data base
        if (!mDbAdapter.isTimeStampInDB(logcat_timestamp)) {
            mDbAdapter.storeCapturedSms(capturedSms);
            mDbAdapter.toEventLog(4, "Detected MWI SMS");
            startPopUpInfo(SmsType.MWI);
        } else {
            log.debug(" Detected Sms already logged");
        }

After Change


        }
    }

    private void parseMwiSms(String[] logcatLines, Date logcat_timestamp) {

        @Cleanup Realm realm = Realm.getDefaultInstance();

        long count = realm.where(SmsData.class).equalTo("timestamp", logcat_timestamp).count();
        // Only alert if the timestamp is not in the data base
        if (count == 0) {
            realm.beginTransaction();

            SmsData capturedSms = realm.createObject(SmsData.class);
            String smsText = findSmsData(logcatLines, null);
            String num = findSmsNumber(logcatLines, null);

            capturedSms.setSenderNumber(num);
            capturedSms.setMessage(smsText);
            capturedSms.setTimestamp(logcat_timestamp);
            capturedSms.setType("MWI");
            setCurrentLocationData(null, capturedSms);

            realm.commitTransaction();

            mDbAdapter.toEventLog(4, "Detected MWI SMS");
            startPopUpInfo(SmsType.MWI);
        } else {
            log.debug("Detected Sms already logged");
        }